
local S = mobs.intllib

-- Toxic Guard

mobs:register_mob("mobs_monster:toxic_guard", {
	type = "monster",
	passive = false,
	attack_type = "dogshoot",
	dogshoot_count_max = 3,
	dogshoot_count2_max = 15,
	shoot_interval = 0.25,
	arrow = "mobs_monster:fireball3",
	shoot_offset = 1,
	dogshoot_switch = 2,
	pathfinding = true,
	reach = 2,
	damage = 7,
	hp_min = 200,
	hp_max = 250,
	armor = 40,
	collisionbox = {-0.5, -0.8, -0.6, 0.6, 1.2, 0.5},
	visual_size = {x=0.75, y=0.75},
	visual = "mesh",
	mesh = "mobs_dungeon_master.b3d",
	textures = {
		{"mobs_toxic_guard.png"},
		{"mobs_toxic_guard2.png"},
		{"mobs_toxic_guard3.png"},
	},
	makes_footstep_sound = true,
	sounds = {
		random = "mobs_dungeonmaster",
		shoot_attack = "mobs_fireball",
		distance = 15,
	},
	walk_velocity = 0.75,
	run_velocity = 1.75,
	knock_back = false,
	pathfinding = true,
	jump = true,
	jump_height = 2.0,
	stepheight = 1.1,
	floats = 0,
	view_range = 20,
	water_damage = 0,
	lava_damage = 50,
	light_damage = 0,
	fear_height = 7,
	animation = {
		stand_start = 0,
		stand_end = 19,
		walk_start = 20,
		walk_end = 35,
		punch_start = 36,
		punch_end = 48,
		speed_normal = 15,
		speed_run = 20,
		shoot_start = 36,
		shoot_end = 48,
	},
	
	-- after death spawn 2 small guards
	on_die = function(self, pos)
				
		local cod = self.cause_of_death or {}
		local def = cod.node and minetest.registered_nodes[cod.node]
		
		-- if dies in lava then bigger explosion to let small guards survive
		if def and def.groups and def.groups.lava then

			mobs:boom(self, pos, 5)
			mobs:effect(pos, 30, "tnt_smoke.png", 2, 6, 4, 0.5, nil, false)

			minetest.sound_play("mobs_boom",
				{pos = pos, max_hear_distance = 30, gain = 1.5}, true)
				
			local num = 2
			for i = 1, num do
				minetest.add_entity({x=pos.x + math.random(-1, 1), y=pos.y + 1, z=pos.z + (math.random(-1, 1))}, "mobs_monster:small_toxic_guard")
			end

		else
			mobs:boom(self, pos, 3)
			mobs:effect(pos, 10, "tnt_smoke.png", 3, 5, 2, 0.5, nil, false)
			minetest.sound_play("mobs_boom",
				{pos = pos, max_hear_distance = 12, gain = 1.5}, true)

		local num = 2
		for i = 1, num do
			minetest.add_entity({x=pos.x + math.random(-1, 1), y=pos.y + 1, z=pos.z + (math.random(-1, 1))}, "mobs_monster:small_toxic_guard")
			end
		end
	end,
})


if not mobs.custom_spawn_monster then
mobs:spawn({
	name = "mobs_monster:toxic_guard",
	nodes = {"default:stone"},
	max_light = 0,
	chance = 21000,
	max_height = -5000,
	active_object_count = 3,
})
end

-- fireball (weapon)
mobs:register_arrow("mobs_monster:fireball3", {
	visual = "sprite",
	visual_size = {x = 1, y = 1},
	textures = {"mobs_fireball3.png"},
	collisionbox = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
	velocity = 12,
	tail = 1,
	tail_texture = "mobs_fireball3.png",
	tail_size = 10,
	glow = 5,
	expire = 0.1,

	hit_player = function(self, player)
		player:punch(self.object, 1.0, {
			full_punch_interval = 1.0,
			damage_groups = {fleshy = 18},
		}, nil)
	end,

	hit_mob = function(self, player)
		player:punch(self.object, 1.0, {
			full_punch_interval = 1.0,
			damage_groups = {fleshy = 14},
		}, nil)
	end,

	hit_node = function(self, pos, node)
		mobs:boom(self, pos, 2)
	end
})

minetest.override_item("default:obsidian", {on_blast = function() end})


mobs:register_egg("mobs_monster:toxic_guard", S("Toxic Guard"), "fire_basic_flame.png", 1)


mobs:alias_mob("mobs:toxic_guard", "mobs_monster:toxic_guard")

-- Small Toxic Guard

mobs:register_mob("mobs_monster:small_toxic_guard", {
	type = "monster",
	passive = false,
	attack_type = "explode",
	damage = 100,
	explosion_radius = 3,
	explosion_damage_radius = 5,
	explosion_timer = 2,
	allow_fuse_reset = true,
	stop_to_explode = false,
	pathfinding = true,
	reach = 3.5,
	damage = 7,
	hp_min = 40,
	hp_max = 40,
	armor = 80,
	collisionbox = {-0.3, -0.5, -0.3, 0.3, 0.8, 0.3},
	visual_size = {x=0.50, y=0.50},
	visual = "mesh",
	mesh = "mobs_dungeon_master.b3d",
	textures = {
		{"mobs_toxic_guard.png"},
		{"mobs_toxic_guard2.png"},
		{"mobs_toxic_guard3.png"},
	},
	makes_footstep_sound = true,
	sounds = {
		random = "mobs_dungeonmaster2",
		fuse = "tnt_ignite",
	},
	walk_velocity = 2,
	run_velocity = 3,
	knock_back = false,
	pathfinding = true,
	jump = true,
	jump_height = 2.0,
	stepheight = 1.1,
	floats = 0,
	view_range = 30,
	drops = {
		{name = "default:mese_crystal_fragment", chance = 1, min = 9, max = 14},
		{name = "mobs:leather", chance = 1, min = 3, max = 7},
		{name = "default:mese_crystal", chance = 1, min = 3, max = 5},
		{name = "default:diamond", chance = 3, min = 4, max = 7},
		{name = "default:diamondblock", chance = 2, min = 1, max = 2},
	},
	water_damage = 0,
	lava_damage = 50,
	light_damage = 0,
	fear_height = 7,
	animation = {
		stand_start = 0,
		stand_end = 19,
		walk_start = 20,
		walk_end = 35,
		punch_start = 36,
		punch_end = 48,
		speed_normal = 15,
		speed_run = 20,
	},
	
	on_die = function(self, pos)
		
		mobs:boom(self, pos, 3)
			
		mobs:effect(pos, 10, "tnt_smoke.png", 3, 5, 2, 0.5, nil, false)
	
		minetest.sound_play("mobs_boom",
			{pos = pos, max_hear_distance = 12, gain = 1.5}, true)
	end
})